﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ITOMMS.Entity;
using ITOMMS.Business;
using Watson.Core.Tools;

namespace ITOMMS.Web.Finance
{
    public partial class FinanceExportAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["id"] != null)
                {
                    string sid = Request.Params["id"].ToString();
                    int pid = 0;
                    if (int.TryParse(sid, out pid))
                    {
                        DataShow(pid);
                    }
                }


                if (Request.Params["vid"] != null)
                {
                    string sid = Request.Params["vid"].ToString();
                    int pid = 0;
                    if (int.TryParse(sid, out pid))
                    {
                        DataShow(pid);
                        btnSave.Visible = false;
                    }
                }
            }
        }
        private void DataShow(int troubleId)
        {
            tb每月费用支出表Entity entity = new tb每月费用支出表Entity();
            entity = entity.GetById(troubleId);

            if (entity != null)
            {
                ViewState["Entity"] = entity;

                txt科目编号.Text = entity.科目编号;
                txt科目名称.Text = entity.科目名称;
                txt单据编号.Text = entity.单据编号;
                txt单据编号.Text = entity.单据编号;
                txt1.Text = entity.一月.ToString();
                txt2.Text = entity.二月.ToString();
                txt3.Text = entity.三月.ToString();
                txt4.Text = entity.四月.ToString();
                txt5.Text = entity.五月.ToString();
                txt6.Text = entity.六月.ToString();
                txt7.Text = entity.七月.ToString();
                txt8.Text = entity.八月.ToString();
                txt9.Text = entity.九月.ToString();
                txt10.Text = entity.十月.ToString();
                txt11.Text = entity.十一月.ToString();
                txt12.Text = entity.十二月.ToString();
                txt总计.Text = entity.总计.ToString();
                txt经办人.Text = entity.经办人;




            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Entity.tb每月费用支出表Entity entity = new ITOMMS.Entity.tb每月费用支出表Entity();
                if (ViewState["Entity"] != null)
                {
                    entity = ViewState["Entity"] as tb每月费用支出表Entity;
                }
                else
                {
                    entity.CreateBy = SessionHelper.UserID;
                    entity.CreateDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                }


                entity.科目编号 = txt科目编号.Text;
                entity.科目名称 = txt科目名称.Text;
                entity.单据编号 = txt单据编号.Text;
                entity.单据编号 = txt单据编号.Text;
                if (txt1.Text.Trim() != string.Empty)
                {
                    entity.一月 = decimal.Parse(txt1.Text.ToString());
                }

                if (txt2.Text.Trim() != string.Empty)
                {
                    entity.二月 = decimal.Parse(txt2.Text.ToString());
                }
                if (txt3.Text.Trim() != string.Empty)
                {
                    entity.三月 = decimal.Parse(txt3.Text.ToString());
                }

                if (txt4.Text.Trim() != string.Empty)
                {
                    entity.四月 = decimal.Parse(txt4.Text.ToString());
                }

                if (txt5.Text.Trim() != string.Empty)
                {
                    entity.五月 = decimal.Parse(txt5.Text.ToString());
                }

                if (txt6.Text.Trim() != string.Empty)
                {
                    entity.六月 = decimal.Parse(txt6.Text.ToString());
                }

                if (txt7.Text.Trim() != string.Empty)
                {
                    entity.七月 = decimal.Parse(txt7.Text.ToString());
                }
                if (txt8.Text.Trim() != string.Empty)
                {
                    entity.八月 = decimal.Parse(txt8.Text.ToString());
                }
                if (txt9.Text.Trim() != string.Empty)
                {
                    entity.九月 = decimal.Parse(txt9.Text.ToString());
                }
                if (txt10.Text.Trim() != string.Empty)
                {
                    entity.十月 = decimal.Parse(txt10.Text.ToString());
                }
                if (txt11.Text.Trim() != string.Empty)
                {
                    entity.十一月 = decimal.Parse(txt11.Text.ToString());
                }
                if (txt12.Text.Trim() != string.Empty)
                {
                    entity.十二月 = decimal.Parse(txt12.Text.ToString());
                }

                if (txt总计.Text.Trim() != string.Empty)
                {
                    entity.总计 = decimal.Parse(txt总计.Text.ToString());
                }
           
                entity.经办人 = txt经办人.Text;

 

                entity.ModifyBy = SessionHelper.UserID;
                entity.ModifyDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));


                entity.SaveOrUpdate(entity);
                ViewState["Entity"] = entity;
                MessageboxInfo.MessageBox(this, MessageType.SUCCEEDED, "保存成功");
            }
            catch (Exception ex)
            {
                log4netHelper.error(ex);
                MessageboxInfo.MessageBox(this, MessageType.ERROR, "保存失败");
            }

        }
    }
}
